import { MockMethod } from 'vite-plugin-mock'
interface User {
  name: string,
  password: string,
  power: string[]
}
const users: User[] = [
  {
    name: 'supperAdmin',
    password: '123456',
    power: ['超级管理员']
  },
  {
    name: 'admin',
    password: '123456',
    power: ['管理员']
  },
  {
    name: 'xg',
    password: '123456',
    power: ['普通用户']
  },
  {
    name: 'xg1992',
    password: '123456',
    power: ['普通会员']
  }
]
// 定义传入的参数
type params = {
  username: string
  password: string
}
export default [
  {
    url: '/login',
    method: 'post',
    response({ body }: { body: params }) {
      console.log(body)
      const userInfo = users.find(item => body.username === item.name && body.password === item.password)
      if(userInfo?.name) {
        return {
          code: 0,
          data: {
            msg: '登录成功',
            userInfo
          }
        }
      } else {
        return {
          code: 1,
          data: {
            msg: '用户名或密码错误'
          }
        }
      }
    }
  }
] as MockMethod[]